<?php
/**
 * 车辆相关接口请求参数验证器
 * Created by PhpStorm.
 * User: LRChang
 * Date: 2018/6/08
 * Time: 10:52
 * Mail: hjklrchang@qq.com
 */

namespace app\adminapi\validate;

use app\base\validate\BaseValidate;

class CarValidate extends BaseValidate
{
    protected $rule = [
        'page' => 'isPositiveInt',
        'pagenum' => 'isPositiveInt',
        'where_json' => 'isWhereJson',
        'car_id'=>'require|isPositiveInt',
        'company_id'=>'isPositiveInt',
        'entrust_company_id'=>'>=:0',
        'car_type_id'=>'isPositiveInt',
        'area_id'=>'integer',
        'car_brand_id'=>'isPositiveInt',
        'car_model_id'=>'integer',
        'car_series_id'=>'integer',
        'car_use_id'=>'integer',
        'car_rental_id'=>'integer',
        'entrust_rental_id'=>'integer',
        'entrust_use_id'=>'integer',
        'is_beidou'=>'in:0,1',
        'from_id'=>'integer',
        'number'=>'max:50',
        'source'=>'in:0,1,2,3',
        'structure'=>'in:1,2,3',
        'colour'=>'max:10',
        'gearbox_type'=>'in:1,2,3',
        'displacement'=>'max:10',
        'car_age'=>'integer',
        'energy_type'=>'integer|max:1',
        'engine_no'=>'require|max:100',
        'chassis_no'=>'max:100',
        'vin'=>'max:100',
        'carry'=>'integer',
        'buy_date'=>'dateFormat:Y-m-d',
        'buy_money'=>'>=:0',
        'mileage'=>'integer',
        'latitude'=>'max:32',
        'longitude'=>'max:32',
        'car_state'=>'in:1,2',
        'driving_license_issued'=>'dateFormat:Y-m-d',
        'driving_license_effective'=>'dateFormat:Y-m-d',
        'prop'=>'max:255',
        'state'=>'in:1,9',
        'driving_license_img'=>'行驶证正本图片|||',
        'driving_license_img2'=>'行驶证副本图片|||',
        'front_img'=>'max:100',
        'back_img'=>'max:100',
        'side_img'=>'max:100',
        'engine_img'=>'max:100',
        'business_insurance_company'=>'max:100',
        'business_policy_no'=>'max:100',
        'business_policy_effective'=>'dateFormat:Y-m-d',
        'phone'=>'number|min:11|max|15',
        'rent_company'=>'max:255',
        'business_policy_img'=>'max:100',
        'compulsory_policy_no'=>'max:100',
        'compulsory_policy_effective'=>'dateFormat:Y-m-d',
        'compulsory_policy_img'=>'max:100',
        'register_time'=>'dateFormat:Y-m-d H:i:s',
        'car_ids' => 'require|checkIDs',
        'car_audit_id'=>'integer',
    ];

    // 默认值
    protected $default = [
        'page' => 1,
        'pagenum' => 20,
        'where_json' => '',
        'fields' => '*',
        'area_id' => 4,
    ];

    protected $message = [
        'page.isPositiveInt' => '页数只能为正整数',
        'pagenum.isPositiveInt' => '每页数量只能为正整数',
        'fields.isNotEmpty' => '字段不能为空',
        'where_json.isWhereJson' => '不是合法的json字符串',
        'car_ids.checkIDs' => "maintenance_id 必须为正整数，多个请用','号连接"
    ];

    protected $scene = [
        'list' => ['page' ,'pagenum', 'fields', 'where_json'],
        'add' => [
            'car_type_id',
            'company_id',
            'entrust_company_id',
            'area_id',
            'car_brand_id',
            'car_model_id',
            'car_series_id',
            'car_use_id',
            'car_rental_id',
            'entrust_rental_id',
            'entrust_use_id',
            'is_beidou',
            'from_id',
            'number',
            'source',
            'structure',
            'colour',
            'gearbox_type',
            'displacement',
            'car_age',
            'energy_type',
            'engine_no',
            'chassis_no',
            'vin',
            'carry',
            'buy_date',
            'buy_money',
            'mileage',
            'latitude',
            'longitude',
            'car_state',
            'driving_license_issued',
            'driving_license_effective',
            'prop',
            'state',
            'driving_license_img',
            'driving_license_img2',
            'front_img',
            'back_img',
            'side_img',
            'engine_img',
            'business_insurance_company',
            'business_policy_no',
            'business_policy_effective',
            'phone',
            'rent_company',
            'business_policy_img',
            'compulsory_policy_no',
            'compulsory_policy_effective',
            'compulsory_policy_img',
            'register_time',
            'car_audit_id',
        ],
        'edit' => [
            'car_id',
            'car_type_id',
            'company_id',
            'entrust_company_id',
            'area_id',
            'car_brand_id',
            'car_model_id',
            'car_series_id',
            'car_use_id',
            'car_rental_id',
            'entrust_rental_id',
            'entrust_use_id',
            'is_beidou',
            'from_id',
            'number',
            'source',
            'structure',
            'colour',
            'gearbox_type',
            'displacement',
            'car_age',
            'energy_type',
            'engine_no',
            'chassis_no',
            'vin',
            'carry',
            'buy_date',
            'buy_money',
            'mileage',
            'latitude',
            'longitude',
            'car_state',
            'driving_license_issued',
            'driving_license_effective',
            'prop',
            'state',
            'driving_license_img',
            'driving_license_img2',
            'front_img',
            'back_img',
            'side_img',
            'engine_img',
            'business_insurance_company',
            'business_policy_no',
            'business_policy_effective',
            'phone',
            'rent_company',
            'business_policy_img',
            'compulsory_policy_no',
            'compulsory_policy_effective',
            'compulsory_policy_img',
            'register_time',
        ],
        'delete' => [ 'car_ids' ],
    ];
}